﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllGRNbyStatusDataAction: BestLifeDataAction<List<GRN>>
    {
        private string GvStatus;
        public BestLifeGetAllGRNbyStatusDataAction(string PStatus)
        {
            GvStatus = PStatus;
        }

        public override List<GRN> Body(SqlConnection PConn)
        {
            try
            {
                List<GRN> LvList = new List<GRN>();

                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetGRNDetailsByStatus";
                LvCommand.Parameters.Add(new SqlParameter("@Status", GvStatus));
           
                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    GRN LvGRN = new GRN();
                    LvGRN.GRN_Id = LvReader.GetValue(0).ToString();
                    //LvGRN.GRN_Date = LvReader.GetValue(1).ToString();
                    LvGRN.Sup_ID = LvReader.GetValue(2).ToString();
                    //LvGRN.Total = LvReader.GetValue(3).ToString();
                    LvGRN.status = LvReader.GetValue(4).ToString();
                    LvGRN.Branch_Id = LvReader.GetValue(5).ToString();
                    LvGRN.Book_GRNno = LvReader.GetValue(6).ToString();
                    LvGRN.Sup_Bill_No = LvReader.GetValue(7).ToString();
                    LvGRN.User_Id = LvReader.GetValue(8).ToString();
                    //LvGRN.Date_Create = LvReader.GetValue(9).ToString();
                    LvGRN.PO_Id = LvReader.GetValue(10).ToString();
                    LvList.Add(LvGRN);
                }


                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
